
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Using iterators &#8212; Leo 6.7.2 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/classic.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../_static/sphinx_highlight.js"></script>
    
    <script src="../../_static/sidebar.js"></script>
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Building scripts from outlines" href="slide-008.html" />
    <link rel="prev" title="Iterators" href="slide-006.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="slide-008.html" title="Building scripts from outlines"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="slide-006.html" title="Iterators"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../leo_toc.html">Leo 6.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../toc-more-links.html" >More Leo Links</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../slides.html" >Slides</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="scripting-leo.html" accesskey="U">Scripting Leo</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Using iterators</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="using-iterators">
<h1>Using iterators<a class="headerlink" href="#using-iterators" title="Permalink to this heading">¶</a></h1>
<p>Iterators give access to all the data in a Leo outline. For example, the following script prints all headlines in an outline, indented to show outline level:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">all_positions</span><span class="p">():</span>
    <span class="n">g</span><span class="o">.</span><span class="n">es</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="o">*</span><span class="n">p</span><span class="o">.</span><span class="n">level</span><span class="p">(),</span><span class="n">p</span><span class="o">.</span><span class="n">h</span><span class="p">)</span>
</pre></div>
</div>
<p>The output of this script, when run from LeoDocs.leo, will look something like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Startup</span>
 <span class="nd">@file</span> <span class="n">doc</span><span class="o">-</span><span class="n">startup</span><span class="o">.</span><span class="n">txt</span>
  <span class="nd">@chapters</span>
  <span class="n">Buttons</span>
   <span class="n">Disabled</span> <span class="n">buttons</span>
<span class="o">...</span> <span class="ow">and</span> <span class="n">hundreds</span> <span class="n">of</span> <span class="n">other</span> <span class="n">nodes</span><span class="o">.</span>
</pre></div>
</div>
<p><em>Note</em>: p.level() is a method of the position class that returns the outline level of the node at position p: 0 for top-level nodes, 1 for their children, and so on.</p>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../leo_toc.html">
              <img class="logo" src="../../_static/LeoLogo.svg" alt="Logo"/>
            </a></p>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="slide-006.html"
                          title="previous chapter">Iterators</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="slide-008.html"
                          title="next chapter">Building scripts from outlines</a></p>
  </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>

      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="slide-008.html" title="Building scripts from outlines"
             >next</a> |</li>
        <li class="right" >
          <a href="slide-006.html" title="Iterators"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../leo_toc.html">Leo 6.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../toc-more-links.html" >More Leo Links</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../slides.html" >Slides</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="scripting-leo.html" >Scripting Leo</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Using iterators</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 1997-2023, Edward K. Ream.
      Last updated on February 28, 2023.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
    </div>
  </body>
</html>